import { useDeviceInfo } from '@/store/modules/deviceInfo';
import { computed } from 'vue';

const useDeviceInfoStore = useDeviceInfo();

export const dataEncryptionModeOptions = [
  {
    label: '不加密',
    value: 0,
  },
  {
    label: 'AES256',
    value: 1,
  },
  {
    label: 'AES128',
    value: 2,
    disabled: true,
  },
  {
    label: 'DES',
    value: 3,
  },
];

export const spanOptions = [
  {
    label: '1.25MHz',
    value: 8,
  },
  {
    label: '2.5MHz',
    value: 0,
  },
  {
    label: '5MHz',
    value: 1,
  },
  {
    label: '10MHz',
    value: 2,
  },
  {
    label: '20MHz',
    value: 3,
  },
];

export const freqModeOptions = [
  {
    label: '单频点',
    value: 'single',
  },
  {
    label: '智能选频',
    value: 'smart',
  },
  //   {
  //     label: '异频收发',
  //     value: 'dual',
  //   },
];

export const rfDisableOptions = [
  {
    label: '所有通道全开',
    value: 0,
  },
  {
    label: '关闭rf1通道',
    value: 1,
  },
  {
    label: '关闭rf2通道',
    value: 2,
  },
  {
    label: 'rf1/rf2通道都关闭',
    value: 3,
  },
];

export const powerAttenOptions = computed(() => {
  return rfCalLabel(useDeviceInfoStore.getPowerMax, useDeviceInfoStore.getPowerMaxAtten);
});

export const powerAtten2Options = rfCalLabel(
  useDeviceInfoStore.getPowerMax,
  useDeviceInfoStore.getPowerMaxAtten2
);

export function rfCalLabel(powerMax: number, powerMaxAtten: number) {
  const labelObjs = [] as { value: number; label: string }[];
  for (let i = powerMaxAtten; i <= 90; i++) {
    const power = Math.pow(10, (powerMax - i + powerMaxAtten) / 10);
    const obj = {} as { value: number; label: string };
    obj.value = i;
    // console.log(power)
    if (power >= 1000) {
      // console.log(Math.round(power) / 1000, 'W')
      // labelArr.push(`${Math.round(power) / 1000} W`)
      obj.label = `${Math.round(power) / 1000} W`;
    } else if (power >= 10) {
      // console.log(Math.round(power), 'mW')
      // labelArr.push(`${Math.round(power)} mW`)
      obj.label = `${Math.round(power)} mW`;
    } else if (power > 1) {
      // console.log(Math.round(power * 100) / 100, 'mW')
      // labelArr.push(`${Math.round(power * 100) / 100} mW`)
      obj.label = `${Math.round(power * 100) / 100} mW`;
    } else if (power >= 0.01) {
      // console.log(Math.round(power * 1000), 'uW')
      // labelArr.push(`${Math.round(power * 1000)} uW`)
      obj.label = `${Math.round(power * 1000)} uW`;
    } else if (power > 0.001) {
      // console.log(Math.round(power * 1000 * 100) / 100, 'uW')
      // labelArr.push(`${Math.round(power * 1000 * 100) / 100} uW`)
      obj.label = `${Math.round(power * 1000 * 100) / 100} uW`;
    } else if (Math.round(power * 1000 * 1000) >= 10) {
      // console.log(Math.round(power * 1000 * 1000), 'nW')
      // labelArr.push(`${Math.round(power * 1000 * 1000)} nW`)
      obj.label = `${Math.round(power * 1000 * 1000)} nW`;
    } else {
      obj.label = `${Math.round(power * 1000 * 1000 * 100) / 100} nW`;
    }
    labelObjs.push(obj);
  }
  // console.log(labelObjs)
  return labelObjs.reverse();
}

export const dataTransferModeOptions = [
  {
    label: 'Ip模式',
    value: 0,
  },
  {
    label: 'Mac模式',
    value: 1,
  },
];
